#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# This program is free software; you can redistribute it and/or modify  
# it under the terms of the GNU General Public License as published by  
# the Free Software Foundation; either version 2 of the License, or     
# (at your option) any later version.                                   
#                                                                         
# A copy of the license can be found in the license.txt file supplied   
# with this software or at: http://www.gnu.org/copyleft/gpl.html       
#



class   CodecChain(object) :
    
    def __init__(self) :
        self._entries = []
        self._count_entries = len(self._entries)
        ## __init__()

    def clear(self) :
        self._entries = []
        self._count_entries = len(self._entries)
        ## clear()

    def add(self, codecer, name=None) :
        self._entries.append( codecer )
        self._count_entries = len(self._entries)
        ## add()

    ###################################################################

    def encode(self, data_in) :
        data = data_in
        for i in range(self._count_entries) :
            codecer = self._entries[ i ]
            data = codecer.encode( data )

        return data
        ## encode()


    def decode(self, data_in) :
        data = data_in
        for i in range(self._count_entries - 1, -1, -1) :
            codecer = self._entries[ i ]
            data = codecer.decode( data )

        return data
        ## decode()

    ###################################################################


    ## class CodecChain


